Description:
SSU detects if a method contains a
switch
on a field
of the containing class. A field must be of an integral type; it may
be accessed either directly or via an accessor method. Such
switch
statements should often be replaced with the usage of several subclasses.
Incorrect:
class Node {
private int kind;
void print() {
switch (kind) {
case ADD:
...
case SUB:
...
}
}
}
Correct:
abstract class Node {
internal abstract void print();
}
class AddNode : Node {
internal override void print() {
...
}
}
class SubNode : Node {
internal override void print() {
...
}
}
Refactoring: